/**
 * @author 徐楠
 * @date 2022/5/13 8:34
 * @version 1.0
 */

package com.xunan.likou;

public class CompareVersionNumber {
    public static void main(String[] args) {
        /*int i = compareVersion("1.01", "1.001");
        int i1 = compareVersion("1.01", "1.0.0");
        int i2 = compareVersion("0.1", "1.0");*/
        int i3 = compareVersion("1.0.1", "1");

        System.out.println(i3);
    }

    public static int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        for (int i = 0; i < v1.length || i < v2.length; ++i) {
            int x = 0;
            int y = 0;
            if (i < v1.length) {
                x = Integer.parseInt(v1[i]);
            }
            if (i < v2.length) {
                y = Integer.parseInt(v2[i]);
            }
            if (x > y) {
                return 1;
            }
            if (x < y) {
                return -1;
            }
        }
        return 0;

    }
}
